﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ibba.agil.core.common;
using ibba.agil.core;

namespace ibba.agil.data.data
{
    public class tbagi001EvenKey : IDataKey
    {
        public int codGrupEven { get; set; }
        public int codEven { get; set; }
        public string codTipoFortItgr { get; set; }
    }

    public class tbagi001Even_COL : CollectionData<tbagi001EvenKey, tbagi001Even_ENT>
    {
        private manager.tbagi001Even_COM _manager;
        private Criteria<CriteriaInfo, object> _pesquisa;

        public tbagi001Even_COL()
        {
            _manager = new manager.tbagi001Even_COM();
        }

        public override List<tbagi001Even_ENT> Find(tbagi001EvenKey key)
        {
            #region Implementacao do Criterio de Pesquisa

            _pesquisa = new Criteria<CriteriaInfo, object>();
            if (key.codGrupEven > 0)
                _pesquisa.Add(new CriteriaInfo()
                {
                    EntityData = new tbagi001Even_ENT(),
                    LikePattern = LikePattern.Both,
                    LogicalType = LogicalOperator.AND,
                    NameProperty = "codGrupEven",
                    SearchType = LogicalComparator.EQUAL
                }, key.codGrupEven);

            if (key.codEven > 0)
                _pesquisa.Add(new CriteriaInfo()
                {
                    EntityData = new tbagi001Even_ENT(),
                    LikePattern = LikePattern.Both,
                    LogicalType = LogicalOperator.AND,
                    NameProperty = "codEven",
                    SearchType = LogicalComparator.EQUAL
                }, key.codEven);


            if (!string.IsNullOrEmpty(key.codTipoFortItgr))
                _pesquisa.Add(new CriteriaInfo()
                {
                    EntityData = new tbagi001Even_ENT(),
                    LikePattern = LikePattern.Both,
                    LogicalType = LogicalOperator.AND,
                    NameProperty = "codTipoFortItgr",
                    SearchType = LogicalComparator.EQUAL
                }, key.codTipoFortItgr);

            #endregion

            return _manager.Where(CriteriaFind);
        }

        protected override Criteria<CriteriaInfo, object> CriteriaFind()
        {
            return _pesquisa;
        }
    }
}
